layui.define(['Router','laytpl',"Zutil"],function(exports) {
	var Router = layui.Router;
	var laytpl = layui.laytpl;
	var Zutil = layui.Zutil;
	var Url=Router.link;
	
	$("#ForinpTel").focus(function(){
		var vuser = $("#ForinpTel").val(); //文本框的值
		var vLength = vuser.length;
		if (vLength == 0) {
			$(this).css("border","1px solid #0032d2").siblings().html("请输入正确的手机号码").css("color","#999");
		}
		return false;
	});
	var validCode = false;
	var  bool = false;
	$("#ForinpTel").blur(function() {
		var vmobile = $("#ForinpTel").val(); //文本框的值
		var vLength = vmobile.length;
		if (vLength == 0) { //如果为空
			$(this).css("border","1px solid #ff001a").siblings().html("请输入手机号码").css("color","#FF001A");
		} else { //如果文本不为空
			if (/^1[34578]\d{9}$/.test(vmobile)) {
				$(this).css("border","").siblings().html("").css("color","");
				validCode = true;
				bool = true;
				return true;
			} else {
				$(this).css("border","1px solid #ff001a").siblings().html("请输入正确的手机号码").css("color","#FF001A");
				return false;
			}
		}
	});//手机号验证
	
	$("#forPwd").focus(function() {
		var vpwd = $("#forPwd").val(); //文本框的值
		var vLength = vpwd.length;
		if (vLength == 0) {
			$(this).css("border","1px solid #0032d2").siblings().html("密码至少包含字母、数字、符号两种，6-22个字符").css("color","#999");
		}
		return false;
	});
	$("#forPwd").blur(function() {
		var vpwd = $("#forPwd").val(); //文本框的值
		var vLength = vpwd.length;
		var pwdReg=new RegExp("^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,22}$");
		if (vLength == 0) { //如果为空
			$(this).css("border","1px solid #ff001a").siblings().html("密码至少包含字母、数字、符号两种，6-22个字符").css("color","#FF001A");
		} else { //如果文本不为空
			if (vLength >= 2 && vLength <= 18) { //如果格式正确
				if (pwdReg.test(vpwd)) {
					$(this).css("border","").siblings().html("");
					return true;
				} else {
					$(this).css("border","1px solid #ff001a").siblings().html("密码至少包含字母、数字、符号两种，6-22个字符").css("color","#FF001A");
					return false;
				}
			} else { //格式不正确
				$(this).css("border","1px solid #ff001a").siblings().html("密码至少包含字母、数字、符号两种，6-22个字符").css("color","#FF001A");
				return false;
			}
		}
	});//密码验证
	
	var pwd2 = $("#forPwdNext"); //确认密码
	pwd2.focus(function() {
		var vpwd2 = $("#forPwdNext").val(); //文本框的值
		var vLength = vpwd2.length;
		if (vLength == 0) {
			$(this).css("border","1px solid #0032d2").siblings().html("密码至少包含字母、数字、符号两种，6-22个字符").css("color","#999");
		}
	});
	pwd2.blur(function() {
		var vpwd2 = $("#forPwdNext").val(); //文本框的值
		var vpwd = $("#forPwd").val();
		var vLength = vpwd2.length;
		var pwdReg=new RegExp("^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,22}$");
		if (vLength == 0) { //如果为空
			$(this).css("border","1px solid #ff001a").siblings().html("请输入密码").css("color","#FF001A");
		} else { //如果文本不为空
			if (pwdReg.test(vpwd2)) {
				if (vpwd != vpwd2) {
					console.log(vpwd);
					$(this).css("border","1px solid #ff001a").siblings().html("两次密码输入不一致").css("color","#FF001A");
				} else {
					console.log("22")
					$(this).css("border","").siblings().html("");
					return true;
				}
			}
		}
	});//确认密码验证
	
	var registerBool = false;
	$("#fBtnNext").click(function(){
		if(registerBool)return false;
		var ForinpTel = $("#ForinpTel").val();
		var ForinpCode=$("#ForinpCode").val();
		var myreg = /^1[34578]\d{9}$/;
		if (!myreg.test(ForinpTel)) {
			$("#ForinpTel").siblings().html("请输入正确的手机号码");
			$("#ForinpTel").focus();
			return false;
		}
		if (ForinpCode == "") {
			$("#ForinpCode").css("border","1px solid #ff001a");
			$("#ForinpCode").focus();
			return false;
		}
		var pwd = $("#forPwd").val();
		var pwd2 = $("#forPwdNext").val();
		var myreg = /^1[34578]\d{9}$/;
		var myregmima = new RegExp("^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,22}$");
		if (!myregmima.test(pwd)) {
			$("#forPwd").siblings().html("密码至少包含字母、数字、符号两种，6-22个字符");
			$("#forPwd").focus();
			return false;
		}
		var myregqrmm = /^{pwd.text}$/;
		if (pwd != pwd2) {
			$("#forPwdNext").siblings().html("两次密码输入不一致");
			$("#forPwdNext").focus();
			return false;
		}
		var fogPwdData={
			phone:ForinpTel,
			password:pwd2,
			SmsCode:ForinpCode
		};
		$.post(Url.user.fogPwd,fogPwdData,function(result){
			if(result.resultCode==200){
				layer.msg('修改成功!',{icon:1,time:1000});
				window.location.href ='/user/modules/login/login.html';
			}else{
				layer.msg(result.message,{icon:2,time:1000});
				
			}
		});
//		window.location.href="/ceca_two/modules/user/login/registerNext.html";
//		registerBool = true;
	});
	var mobilePho;
	var codeTime;
	$("#btnCode").click(function(){
		if($("#btnCode").hasClass("disabled")){
			return;
		}
		$("#btnCode").addClass("disabled").html("重新发送(<span>60</span>)");
		mobilePho=$("#ForinpTel").val();
		if(!Zutil.checkPhone(mobilePho)){
				$("#btnCode").removeClass("disabled").html("重新发送");
				clearInterval(codeTime);
			return;
		}
		codeTime=setInterval(function(){
			$("#btnCode span").html(Number($("#btnCode span").html())-1);
			if(Number($("#btnCode span").html())<=0){
				$("#btnCode").removeClass("disabled").html("重新发送");
				clearInterval(codeTime);
			}
		},1000);
		var getFogCodeData={
			mobile:mobilePho
		};
		$.post(Url.user.getFogCode,getFogCodeData,function(result){
			if(result.resultCode==200){
				layer.msg('发送成功!',{icon:1,time:1000});
			}else{
				layer.msg(result.message,{icon:2,time:1000});
				$("#btnCode").removeClass("disabled").html("重新发送");
				clearInterval(codeTime);
			}
		});
		
	});
	$("#fBtnSubmit").click(function(){
		if(registerBool)return false;
		var forPwdNext = $("#forPwdNext").val();
		var forPwd=$("#forPwd").val();
		var myregmima = new RegExp("^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,22}$");
		if (!myregmima.test(forPwd)) {
			$("#forPwd").siblings().html("密码至少包含字母、数字、符号两种，6-22个字符");
			$("#forPwd").focus();
			return false;
		}
		var myregqrmm = /^{forPwd.text}$/;
		if (forPwd != forPwdNext) {
			$("#forPwdNext").siblings().html("两次密码输入不一致");
			$("#forPwdNext").focus();
			return false;
		}
		window.location.href="/ceca_two/modules/user/login/forgetpasswordSuccess.html";
		registerBool = true;
	});
	exports('forget',{}); //注意，这里是模块输出的核心，模块名必须和use时的模块名一致
});
